<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>联盟管理</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/style.css"/>
		<link rel="stylesheet" href="../css/iconfont.css" />
		<link rel="stylesheet" href="../css/wallet.css" />
		<style type="text/css">
			.fjysq_slis{padding-bottom: 70px; background: white;}
			#item_manage,#item_list{color: #FF7831; display: none; height: 2.5rem; font-size: 1rem; width: 60%; margin: .7rem 0 0 20%; border-color: #FF7831;}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" href="JavaScript:history.go(-1)"></a>
		    <h1 class="mui-title">联盟管理</h1>
		    
		</header>
		<div class="mui-content fjysq_content">
			<ul class="fjysq_slis">
				<li class="clearfix" style="text-align: center;">
					<div class="gerenzl_top img-click" style="padding-left: 42%;">
		   		 		<div class="actions">
								<button class="file-btn beijingkuang">
					                <input type="hidden" name="thumb" id="thumb" />
					                <input type="file" id="upload" value="选择图片文件" multiple />
					                <span><img class='img_1' id='img_list' ></span>
					            </button>
						</div>
						<!--$('#upload').on('change', function() {
								$(".beijingkuang").hide();
								readFile1(this,"thumb",1);
						});-->
					   <div style="font-size: 1rem; line-height: 1.5rem;">LOGO</div>
					</div>
				</li>
				<li class="clearfix">
					<div class="left">名称：</div>
					<div class="right clearfix"><input type="text" placeholder="联盟名称" id='name'></div>
				</li>
				<li class="clearfix">
					<div class="left">单客次广告费：</div>
					<div class="right clearfix" style="text-align: left;"><lable disabled="true" type="text" id='ads_one' onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')" value="0.1" style="width: 80%;margin-right: 5%;">0.1<lable>元</lable></div>
				</li>
				<li class="clearfix">
					<div class="left">电话：</div>
					<div class="right clearfix"><input type="text" id='mobile' placeholder=""></div>
				</li>
				<li class="clearfix">
					<div class="left">描述：</div>
					<div class="right clearfix"><input type="text" id='content' placeholder=""></div>
				</li>
				<li class="clearfix">
					<div class="left">联盟经营范围：</div>
					<div class="right clearfix"><input type="text" id='scope' placeholder=""></div>
				</li>
				<button type="button" id="item_manage" >成员管理</button>
				<button type="button" id="item_list">成员列表</button>
			</ul>
			
			<button type="button" class="fjysq_btn" id='back_union' style="display: none;">退出联盟</button>
			<button type="button" class="fjysq_btn" id='back_union_main' style="display: none;">退出联盟</button>
			
			<button type="button" class="fjysq_btn" id='create_union' style="display: none;">提交申请</button>
			<input type="hidden" id='cut_agent_id'>
			<input type="hidden" id='cut_union_id'>
		</div>
	</body>
</html>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/castapp.js"></script>
<script type="text/javascript" src="../js/layer/layer.min.js"></script>
<script type="text/javascript" src="../js/app.js"></script>
<script>
	$(function(){
		$.ajax({
				url: APP.api_url + 'wallet/my_union',
				data: {
					token		: get_token(),
					uid			: getUid(),
				},
				success: function(data) {
					if(data.code == 201) {	//已创建联盟
						$union_store = data.data;
						$('#cut_union_id').val($union_store['id']);
						$(".beijingkuang").hide();
						//图片地址
						var picture_url = user_tupian($union_store['thumb'],'/images/logo-ma.jpg');
						$('#img_list').append("<img style='width: 80px;height: 80px; margin:0 auto;' src='"+picture_url+"'>");
						$("#name").val($union_store.name);
						$("#ads_one").val($union_store['unnion_ads_money']);
						$("#mobile").val($union_store['tel']);
						$("#content").val($union_store['content']);
						$("#scope").val($union_store['scope']);
						$("#cut_agent_id").val($union_store['agent_id']);
						if($union_store.status == 1){
							$("#create_union").attr('disabled',true);
							$("#create_union").show();
							$('#create_union').text('创建联盟审核中');
						}else if($union_store.status == 2){
							$("#item_manage").show();
							$("#back_union_main").show();
						}
						
					}else if(data.code == 202){
						/*$union_store = data.data.union_store;
						$('#cut_union_id').val($union_store['id']);
						$union_item = data.data.union_item;
						$(".beijingkuang").hide();
						//图片地址
						var picture_url = user_tupian($union_store['thumb'],'/images/logo-ma.jpg');
						$('#img_list').append("<img style='width: 80px;height: 80px; margin:0 auto;' src='"+picture_url+"'>");
						$("#name").val($union_store.name);
						$("#ads_one").val($union_store['unnion_ads_money']);
						$("#mobile").val($union_store['tel']);
						$("#content").val($union_store['content']);
						$("#scope").val($union_store['scope']);
						$("#cut_agent_id").val($union_item['agent_id']);
						if($union_item.apply == 1){
							$("#create_union").attr('disabled',true);
							$("#create_union").show();
							$('#create_union').text('申请加入联盟审核中');
						}else if($union_item.apply == 2){
							$("#item_list").show();
							$("#back_union").show();
						}*/
						$("#create_union").show();
					}else{
						$("#create_union").show();
						
					}
				}
			});
		
		//图片上传
		$('#upload').on('change', function() {
				$(".beijingkuang").hide();
				readFile1(this,"thumb",1);
				$('.beijingkuang').show();
		});
		
		//联盟主退出联盟
		$('#back_union_main').click(function(){
			$.ajax({
				url: APP.api_url + 'wallet/back_union',
				data: {
					token		: get_token(),
					uid			: getUid(),
				},
				success: function(data) {
					layer.msg(data.msg, {
							  time: 2000 
							}, function(){
								location.href=APP.web_root+'shopwallet/alliance_fjlist.html';
							});
				}
			});
		});
		//成员退出联盟
		$('#back_union').click(function(){
			$.ajax({
				url: APP.api_url + 'wallet/remove_member',
				data: {
					token		: get_token(),
					uid			: getUid(),
					agent_id	:$("#cut_agent_id").val()
				},
				success: function(data) {
					layer.msg(data.msg, {
							  time: 2000 
							}, function(){
								location.href=APP.web_root+'shopwallet/alliance_fjlist.html';
							});
				}
			});
		});
		
		//成员管理
		$('#item_manage').click(function(){
			location.href = APP.web_root+'shopwallet/fjysq_memedit.html?union_id='+$('#cut_union_id').val();
		});
		//成员列表
		$('#item_list').click(function(){
			location.href = APP.web_root+'shopwallet/fjysq_memlist.html?union_id='+$('#cut_union_id').val();
		});
		
		$('#create_union').click(function(){
			$("#create_union").attr('disabled',true);
			//联盟图片
			var thumb = $("#thumb").val();
			//联盟名称
			var name = $("#name").val();
			//单客次广告费
			var ads_one = $("#ads_one").val();
			//联盟电话
			var mobile = $("#mobile").val();
			//联盟描述
			var content = $("#content").val();
			//联盟经营范围
			var scope = $("#scope").val();
			var myreg = /^1[3578]\d{9}$/; 
			if(name =="" || content=="" || scope==""){
				$("#create_union").attr('disabled',false);
				layer.msg('请把信息填写完整');
				return false;
			}
			if(thumb=="" || thumb==undefined){
				$("#create_union").attr('disabled',false);
				layer.msg('请上传联盟logo');
				return false;
			}
			 if(!myreg.test(mobile)){
			 	$("#create_union").attr('disabled',false);
		    	layer.msg('请输入有效的手机号码！'); 
		    	return false;
		    }
			
			$.ajax({
				url: APP.api_url + 'wallet/create_union',
				data: {
					token		: get_token(),
					uid			: getUid(),
					thumb		: thumb,
					name		: name,
					ads_one		: 0.1,
					mobile		: mobile,
					content		: content,
					scope		: scope
				},
				success: function(data) {
					if(data.code == 200) {
						layer.msg(data.msg, {
							  time: 2000 
							}, function(){
								location.href=APP.web_root+'shopwallet/alliance_fjlist.html';
							});
					}else{
						layer.msg(data.msg, {
							  time: 2000 
							}, function(){
								location.href=APP.web_root+'shopwallet/alliance_fjlist.html';
							});
					}
				}
			});
		});
	})
</script>
